package com.deviche.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.DouyinViewHolder> {


    Context mContext;

    @NonNull
    @Override
    public DouyinViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        mContext = viewGroup.getContext();
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_douyin_video,viewGroup,false);
//        View view = View.inflate(viewGroup.getContext(), R.layout.item_douyin_video, null);
        DouyinViewHolder viewHolder = new DouyinViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull DouyinViewHolder douyinViewHolder, final int i) {
        douyinViewHolder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext,"点击了第 " + i+" 个" ,Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public int getItemCount() {
        return 30;
    }

    class DouyinViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        //        TextView textView;
        public DouyinViewHolder(@NonNull View itemView) {
            super(itemView);
//            textView = itemView.findViewById(R.id.tv_douyin_item);
            imageView = itemView.findViewById(R.id.tv_douyin_item);
        }
    }
}
